package com.example.serviceconsumer.config;

import io.github.resilience4j.bulkhead.ThreadPoolBulkhead;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
public class BulkheadConfiguration {

    @Bean
    public ThreadPoolBulkhead threadPoolBulkhead() {
        io.github.resilience4j.bulkhead.ThreadPoolBulkheadConfig config = 
            io.github.resilience4j.bulkhead.ThreadPoolBulkheadConfig.custom()
            .maxThreadPoolSize(10)        // 最大并发线程数：10
            .coreThreadPoolSize(5)        // 核心线程数：5
            .queueCapacity(5)             // 队列容量：5
            .keepAliveDuration(Duration.ofMillis(20))  // 最大等待时间：20ms
            .build();

        return ThreadPoolBulkhead.of("testBulkhead", config);
    }
}